﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace Fares
{
    public partial class ArticoleParteneriFrm : FrmRezumat
    {
        private Boolean FolosesteVariante = false;
        private Int32 id_articol=-1;
        public Int32 IdArticol
        {
            set { id_articol = value; }
        }
        public ArticoleParteneriFrm(ModuleClass mc,Boolean _FolosesteVariante):base(mc)
        {
            InitializeComponent();
            workConnString = mc.workConnectionString;
            articoleParteneriDGV.m_AutoCompletionColumns.Add(idPartenerColumn);
            ActiveControl = articoleParteneriDGV;
            idPartenerColumn.DataSource = parteneriBindingSource;
            idPartenerColumn.DisplayMember = "Denumire";
            idPartenerColumn.ValueMember = "IDPartener";
            FolosesteVariante = _FolosesteVariante;
        }

        private void ArticoleParteneriFrm_Load(object sender, EventArgs e)
        {
            this.listBndSourceMain.Add(articoleParteneriBindingSource);
            this.listTableAdaptor.Add(articoleParteneriTableAdapter.Adapter);

            SqlConnection con=DeschideConexiune(workConnString);
            articoleVarianteTableAdapter.Connection = con;
            if (id_articol != -1)
                articoleVarianteTableAdapter.FillByIDArticol(eSRPDataSet.ArticoleVariante, id_articol);
            else
                articoleVarianteTableAdapter.Fill(eSRPDataSet.ArticoleVariante);
            this.parteneriTableAdapter.Connection = con;
            //incarca doar partenerii de pe unitatea curenta
            this.parteneriTableAdapter.FillByUnitate(this.eSRPDataSet.Parteneri,ModuleInfo.CodUnitate);
            this.articoleParteneriTableAdapter.Connection = con;
            if (id_articol == -1)
                this.articoleParteneriTableAdapter.Fill(this.eSRPDataSet.ArticoleParteneri);
            else
            {
                this.articoleParteneriTableAdapter.FillByIdArticol(this.eSRPDataSet.ArticoleParteneri, id_articol);
                eSRPDataSet.ArticoleParteneri.IDArticolColumn.DefaultValue = id_articol;
            }
            if (articoleVarianteBindingSource.Count == 0 || !FolosesteVariante)
                IDVariantaArticolColumn.Visible = false;


            InchideConexiune(con);
            HandleSalvare += Salvare;

        }
    }
}
